package org.java.easyExcel;

import com.alibaba.excel.EasyExcel;
import lombok.extern.slf4j.Slf4j;

import java.io.File;
import java.util.*;

/**
 * @Description easyExcel DEMO
 * @Date 2024/8/30 9:43
 * @Created by 10574
 */
@Slf4j
public class easyExcelDemo {
    private static final String EXCEL_TAIL = ".xls";
    private static final String EXCEL_FILE_NAME = "zhanyurui-" + UUID.randomUUID() + EXCEL_TAIL;

    public static void main(String[] args) {
        importFile();
    }

    public static void importFile() {
        final ZhuZiListener listener = new ZhuZiListener();
        final File file = new File("zhanyurui-faeca4e7-d431-4377-b3c5-9746616fd7ec.xls");
        EasyExcel.read(file, ZhuZi.class, listener).sheet().doRead();
        final List<ZhuZi> datas = listener.getData();
        log.info(Arrays.toString(datas.toArray()));
    }

    public static void exportFile() {
        final File file = new File(EXCEL_FILE_NAME);
        final ZhuZi zhuZi = new ZhuZi(1L, "zyr", "男", "movie", new Date());
        final List<ZhuZi> data = Collections.singletonList(zhuZi);
        EasyExcel.write(file, ZhuZi.class).sheet().doWrite(data);
    }
}
